//
//  CAAddressTableViewCell.m
//  LNH
//
//  Created by twentylx on 2018/1/29.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAAddressTableViewCell.h"

@implementation CAAddressTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.nameLabel];
        [self.bgView addSubview:self.phoneLabel];
        [self.bgView addSubview:self.addressLabel];
        [self.bgView addSubview:self.lineView];
        [self.bgView addSubview:self.defaultButton];
        [self.bgView addSubview:self.editButton];
        [self.bgView addSubview:self.delButton];
        
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.equalTo(self);
            make.top.equalTo(self).offset(20);
            make.bottom.equalTo(self);
        }];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(20);
            make.top.equalTo(self.bgView).offset(20);
        }];
        
        [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView).offset(-30);
            make.top.equalTo(self.nameLabel);
        }];
        
        [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(20);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(15);
            make.right.equalTo(self.bgView).offset(-20);
        }];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.equalTo(self.bgView);
            make.top.equalTo(self).offset(130);
            make.height.mas_equalTo(ONE_PIXEL);
        }];
        
        [_defaultButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(20);
            make.top.equalTo(self.lineView.mas_bottom).offset(15);
            make.width.mas_equalTo(SCREEN_WIDTH/3);
        }];
        
        [_delButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView).offset(-20);
            make.top.equalTo(self.lineView.mas_bottom).offset(15);
        }];
        
        [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.delButton.mas_left).offset(-40);
            make.top.equalTo(self.lineView.mas_bottom).offset(15);
        }];
    }
    return self;
}

#pragma mark get & set
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.text = @"收货人：艾缇薇";
        _nameLabel.font = [UIFont systemFontOfSize:14];
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [UILabel new];
        _phoneLabel.text = @"13125559844";
        _phoneLabel.font = [UIFont systemFontOfSize:14];
        _phoneLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _phoneLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [UILabel new];
        _addressLabel.text = @"广东省广州市白云区 绿地中心1407";
        _addressLabel.font = [UIFont systemFontOfSize:14];
        _addressLabel.numberOfLines = 2;
        _addressLabel.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _addressLabel;
}

- (UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        [_lineView setBackgroundColor:RGBCOLOR(51, 51, 51)];
    }
    return _lineView;
}

- (UIButton *)defaultButton {
    if (!_defaultButton) {
        _defaultButton = [UIButton new];
//        [_defaultButton setBackgroundImage:LMImageNamed(@"address_del") forState:UIControlStateNormal];
//        [_defaultButton setTitle:@"设为默认" forState:UIControlStateNormal];
//        _defaultButton.titleLabel.font = [UIFont systemFontOfSize:14];
//        [_defaultButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _defaultButton.imageEdgeInsets = UIEdgeInsetsMake(0, -25, 0, 0);
//        _defaultButton.titleEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 0);
        
        [_defaultButton setTitle:@"设为默认" forState:UIControlStateNormal];
        [_defaultButton setTitle:@"设为默认" forState:UIControlStateSelected];
        [_defaultButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _defaultButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_defaultButton setImage:[UIImage imageNamed:@"address_default"] forState:UIControlStateSelected];
        [_defaultButton setImage:[UIImage imageNamed:@"shopcart_selectNormal"] forState:UIControlStateNormal];
        _defaultButton.imageEdgeInsets = UIEdgeInsetsMake(0, -60, 0,0);
        _defaultButton.titleEdgeInsets = UIEdgeInsetsMake(0, -45, 0, 0);
    }
    return _defaultButton;
}

- (UIButton *)editButton {
    if (!_editButton) {
        _editButton = [UIButton new];
        [_editButton setTitle:@"编辑" forState:UIControlStateNormal];
        [_editButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _editButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_editButton setImage:[UIImage imageNamed:@"address_edit"] forState:UIControlStateNormal];
        _editButton.imageEdgeInsets = UIEdgeInsetsMake(0, -60, 0,0);
        _editButton.titleEdgeInsets = UIEdgeInsetsMake(0, -45, 0, 0);
    }
    return _editButton;
}

- (UIButton *)delButton {
    if (!_delButton) {
        _delButton = [UIButton new];
        [_delButton setTitle:@"删除" forState:UIControlStateNormal];
        [_delButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _delButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_delButton setImage:[UIImage imageNamed:@"address_del"] forState:UIControlStateNormal];
        _delButton.imageEdgeInsets = UIEdgeInsetsMake(0, -60, 0,0);
        _delButton.titleEdgeInsets = UIEdgeInsetsMake(0, -45, 0, 0);
    }
    return _delButton;
}

#pragma mark func
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
